<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="Articles.aspx.cs" Inherits="Impact.Web.Admin.Articles" EnableEventValidation="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">



    <table class="AdminTable">
        <tr>
            <th>Articles:</th>
            <th class="NonHeader"><asp:DropDownList ID="categories" AutoPostBack="true" runat="server" OnSelectedIndexChanged="Categories_SelectedIndexChanged" /></th>
            <th class="NonHeader">Views</th>
            <th class="NonHeader">Enabled</th>
            <th class="NonHeader">Preview</th>
            <th class="NonHeader">Comments</th>
            <th class="NonHeader">Delete</th>
        </tr>    
    
        <asp:Repeater ID="articleList" runat="server" OnItemCommand="ArticleList_ItemCommand">
            <ItemTemplate>
                <tr>
                    <td><%# ((DateTime)Eval("CreatedOn")).ToString("MMM dd") %></td>
                    <td style="text-align: left; width: 300px;">
                        <a href="EditArticle.aspx?aid=<%# Eval("ArticleID") %>"><%# Eval("Title") %></a>
                    </td>
                    <td style="text-align: center;"><%# Eval("UserViews") %></td>
                    <td style="text-align: center;">
                        <asp:ImageButton ID="toggleButton" CommandName="toggleEnabled" CommandArgument='<%# Eval("ArticleID") %>' 
                            ImageUrl='<%# Convert.ToBoolean(Eval("Enabled")) ? "images/checked.png" : "images/unchecked.png" %>' runat="server" />
                    </td>
                    
                    <td style="text-align: center;">
                        <asp:ImageButton ID="previewButton" CommandName="preview" CommandArgument='<%# Eval("ArticleID") %>'
                            ImageUrl="images/magnifier.png" runat="server" />
                    </td>

                    <td style="text-align: center;">
                        <asp:ImageButton ID="allowComments" CommandName="toggleComments" CommandArgument='<%# Eval("ArticleID") %>' 
                            ImageUrl='<%# (bool)Eval("Category.AllowComments") ?  ((bool)Eval("AllowComments") ? "images/checked.png" : "images/unchecked.png") : "images/grey-x.png" %>' 
                            Enabled='<%# Eval("Category.AllowComments") %>'
                            AlternateText='<%# (bool)Eval("Category.AllowComments") ? ((bool)Eval("AllowComments") ? "Comments are enabled." : "Comments are disabled." ) : "Comments are disabled at the category level." %>'
                            runat="server" />
                            <asp:LinkButton id="manageComments" CommandName="manageComments" CommandArgument='<%# Eval("ArticleId") %>'
                                runat="server">[<%# Eval("Comments.Count")%>]</asp:LinkButton>
                    </td>
                    <td style="text-align: center;">
                        <asp:ImageButton ID="deleteCategory" CommandName="delete" CommandArgument='<%# Eval("ArticleID") %>'
                            ImageUrl="images/red-x.png" runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
        
    <asp:Panel ID="errorPanel" Visible="false" runat="server">
        <tr>
            <td colspan="6"><asp:Label ID="errorLabel" runat="server" /></td>
        </tr>
    </asp:Panel>
    
        <tr>
            <td colspan="6" style="text-align: right;">
                <impact:ImageLinkButton ID="addArticleButton" CssClass="AdminTableButton" runat="server"
                    ImageUrl="images/add.png" Text="Create New Article" OnCommand="NewArticleButtonCommand" />
            </td>
        </tr>
    </table>
    
    
    
    <table class="AdminTable" style="margin-top: 0px;">
        <tr>
            <th style="width: 20px;"><img id="categoryIndicator" src="images/arrow_down.png" alt="" /></th>
            <th style="font-size: 10pt;"><a id="categoriesHeader" href="#">Article Categories</a></th>
        </tr>
        <tr>
            <td colspan="2">
                        
                <div id="articleCategories" style="display: <%= (Boolean.Parse(showCategories.Value)) ? "inherit" : "none" %>;" >
                    <asp:HiddenField ID="showCategories" Value="false" runat="server" />
                    
                    <table style="width: 100%; border-collapse: collapse;">
                        <tr>
                            <th></th>
                            <th class="NonHeader">Template</th>
                            <th class="NonHeader">Articles</th>
                            <th class="NonHeader">Visible?</th>
                            <th class="NonHeader">Comments?</th>
                            <th class="NonHeader">RSS?</th>
                            <th class="NonHeader">Delete</th>
                        </tr>
                    
                        <asp:Repeater ID="articleCategoryList" runat="server" OnItemCommand="CategoryList_ItemCommand">
                            <ItemTemplate>
                                <tr>
                                    <td style="width: 300px;"><%# Eval("Name") %></td>
                                    
                                    <td>
                                        <impact:SelectableDropDownList id="template" AppendDataBoundItems="true" DataSource="<%# GetTemplates() %>"
                                                DataTextField="Name" DataValueField="TemplateId" DefaultSelectedValue='<%# Eval("TemplateId") %>' 
                                                AutoPostBack="true" OnSelectedIndexChanged="CategoryTemplateChanged" runat="server">
                                            <asp:ListItem Text="None" Value="-1"></asp:ListItem>
                                        </impact:SelectableDropDownList>
                                    </td>
                                    
                                    <td style="text-align: center;"><%# GetArticleCount(Container.DataItem) %></td>
                                    
                                    <td style="text-align: center;">
                                        <asp:ImageButton ID="visible" CommandName="toggleVisible" CommandArgument='<%# Eval("CategoryId") %>' 
                                            ImageUrl='<%# Convert.ToBoolean(Eval("MenuVisible")) ? "images/checked.png" : "images/unchecked.png" %>' 
                                            AlternateText='<%# (bool)Eval("MenuVisible") ? "This category is visible in the list of article categories." : "This category is not shown in the list of article categories." %>'
                                            runat="server" />
                                    </td>
                                    
                                    <td style="text-align: center;">
                                        <asp:ImageButton ID="allowComments" CommandName="toggleComments" CommandArgument='<%# Eval("CategoryId") %>' 
                                            ImageUrl='<%# Convert.ToBoolean(Eval("AllowComments")) ? "images/checked.png" : "images/unchecked.png" %>' 
                                            AlternateText='<%# (bool)Eval("AllowComments") ? "Comments are enabled for this entire category." : "Comments are disabled for this entire category." %>'
                                            runat="server" />
                                    </td>
                                    
                                    <td style="text-align: center;">
                                        <asp:ImageButton ID="allowRss" CommandName="toggleRss" CommandArgument='<%# Eval("CategoryId") %>' 
                                            ImageUrl='<%# Convert.ToBoolean(Eval("AllowRss")) ? "images/checked.png" : "images/unchecked.png" %>' 
                                            AlternateText='<%# (bool)Eval("AllowRss") ? "RSS subscriptions are enabled for this category." : "RSS subscriptions are disabled for this category." %>'
                                            runat="server" />
                                    </td>
                                    
                                    <td style="text-align: center;">
                                        <asp:ImageButton ID="deleteCategory" CommandName="delete" CommandArgument='<%# Eval("CategoryID") %>'
                                            ImageUrl="images/red-x.png" runat="server" /></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr>
                            <td colspan="7" style="text-align: center;">
                                <impact:ImageLinkButton ID="addCategoryButton" CssClass="AdminTableButton" Style="" runat="server"
                                    ImageUrl="images/add.png" Text="Add Category" OnCommand="AddCategory_Command" />
                                <asp:Panel ID="newCategoryPanel" Visible="false" runat="server">
                                    <div style="margin: 10px;">New Category: <asp:TextBox ID="newCategoryName" runat="server" /></div>
                                    <impact:SubmitCancel id="newCategorySubmit" OnSubmit="NewCategorySubmit" OnCancel="NewCategoryCancel" runat="server" />
                                </asp:Panel>
                                
                            </td>
                        </tr>
                        
                    </table>
                
                </div>
                
            </td>
        </tr>
    </table>

    <table class="AdminTable" style="margin-top: 0px;">
        <tr>
            <th style="width: 20px;"><img id="tagsIndicator" src="images/arrow_down.png" alt="" /></th>
            <th style="font-size: 10pt;"><a id="tagsHeader" href="#">Tags</a></th>
        </tr>
        <tr>
            <td colspan="2">

                <div id="tags" style="display: <%= (Boolean.Parse(showTags.Value)) ? "inherit" : "none" %>;" >
                    <asp:HiddenField ID="showTags" Value="false" runat="server" />
                    
                    <table style="width: 100%; border-collapse: collapse;">
            
                <asp:Repeater ID="tagsRepeater" OnItemCommand="TagList_ItemCommand" runat="server">
                    <HeaderTemplate>
                        <tr>
                            <th></th>
                             <th class="NonHeader">Articles <span style="font-size: 0.8em;">(enabled)</span></th>
                            <th class="NonHeader">Delete</th>
                        </tr>
                    </HeaderTemplate>
                    
                    <ItemTemplate>
                        <tr>
                            <td><%# Eval("Text") %></td>
                            <td style="text-align: center;">[<%# Eval("Articles.Count") %>]</td>
                            <td style="text-align: center;">
                                <asp:ImageButton ID="deleteTag" CommandName="delete" CommandArgument='<%# Eval("TagId") %>'
                                    ImageUrl="images/red-x.png" runat="server" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    
                </asp:Repeater>
            
                    </table>
                    
                </div>
            
            
            </td>
        </tr>
    </table>       
   
    


    <script type="text/javascript">

        var articlesIndicator = document.getElementById("categoryIndicator");
        var articlesDiv = document.getElementById("articleCategories");
        
        var tagsIndicator = document.getElementById("tagsIndicator");
        var tagsDiv = document.getElementById("tags");
    
        function toggleArticlesArrow()
        {
            if(articlesDiv.style.display == "none")
            {
                articlesIndicator.src = "images/arrow_down.png";
            }
            else
            {
                articlesIndicator.src = "images/arrow_up.png";
            }
        }
    
        function toggleTagsArrow()
        {
            if(tagsDiv.style.display == "none")
            {
                tagsIndicator.src = "images/arrow_down.png";
            }
            else
            {
                tagsIndicator.src = "images/arrow_up.png";
            }
        }
        
        
        $(function()
        {
            $("#categoriesHeader").click(function()
            {
                $("#articleCategories").slideToggle( "slow", function() { toggleArticlesArrow(); } );
                return false;
            });
            
            $("#tagsHeader").click(function()
            {
                $("#tags").slideToggle( "slow", function() { toggleTagsArrow(); } );
                return false;
            });
        
        });
        
    </script>



</asp:Content>
